<?php 
require 'Model.php';
class VideoModel extends Model{
	function __Construct(){
		parent::__Construct();
		$this->mod='videos';
	}
	function getList()
	{
		$sql="select * from {$this->mod}";
		$data=$this->conn->query($sql);
		return $data;
	}
			function add1($data)
		{
			if(!empty($_FILES["pic"]["name"])){
				$pic = $this->uploadfile('pic','./upload1/',array('jpg','gif','png'));
			}
			else{
				$pic='';
			}
			$video = array(
				'videoname' => $data['videoname'],  
				'tid' => $data['tid'],
				'pic'=>$pic,
				'intro' => $data['intro'],
				'address'=>$data['address']
				);
			$keys = implode(',',array_keys($video));
			$values = implode("','", array_values($video));
			$sql="insert into videos ({$keys}) VALUES ('{$values}')";

			$result = $this->conn->query($sql);
			return $result;
		}
		function getVideoByID($id){
			$sql = "select * from videos where vid=".$id;
			$result = $this->conn->query($sql);
			return $result;
		}
		function update1($data)
		{
			$user = array(
				'videoname' => $data['videoname'],  
				'tid' => $data['tid'],
				'intro' => $data['intro'],
				'address'=> $data['address']
				);
			if(!empty($_FILES["pic"]["name"])){
				$pic = $this->uploadfile('pic','./upload1/',array('jpg','gif','png'));
				$user['pic'] = $pic;
			}			
			$sets = '';
			foreach ($user as $key=>$val){
				$sets.=$key."='".$val."',";
			}
			    $sets=rtrim($sets,','); //去掉SQL里的最后一个逗号
			    
			    $sql="UPDATE videos SET {$sets} where vid=".$data['id'];
			  //执行SQL语句
			    $result = $this->conn->query($sql);
			    return $result;		    
			}
				function delete1($id)
			{
				$sql = "delete from videos where vid=".$id;
				$result = $this->conn->query($sql);
				return $result;
			}
}


 ?>